home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-11-08 | 7.5 KB | 242 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: FWDrCmd.h
- // Release Version: $ 1.0d11 $
- //
- // Copyright: © 1995 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
- // This file contains two command classes that handle Drag-and-Drop.
- // These commands must be subclassed to add Undo support for the following actions:
- // drag-move within a part FW_CDropCommand
- // drag-move to a different part FW_CDropCommand and FW_CDragCommand
- // drag-copy FW_CDropCommand
- //========================================================================================
-
- #ifndef FWDRCMD_H
- #define FWDRCMD_H
-
- #ifndef FWCMD_H
- #include "FWCmd.h"
- #endif
-
- #ifndef FWPOINT_H
- #include "FWPoint.h"
- #endif
-
- #ifndef FWREGION_H
- #include "FWRegion.h"
- #endif
-
- // ----- OpenDoc Includes -----
-
- #ifndef _ODTYPES_
- #include <ODTypes.h>
- #endif
-
- #ifndef SOM_ODDraft_xh
- #include <Draft.xh>
- #endif
-
- #if FW_LIB_EXPORT_PRAGMAS
- #pragma lib_export on
- #endif
-
- //==============================================================================
- // Constants
- //==============================================================================
-
- const ODCommandID FW_kDragCommand = 101; // MEB what should these be?
- const ODCommandID FW_kDropCommand = 102;
-
- //==============================================================================
- // Forward Declarations
- //==============================================================================
-
- class FW_CLASS_ATTR FW_CPart;
- class FW_CLASS_ATTR FW_CFrame;
- class FW_CLASS_ATTR FW_CSelection;
- class FW_CLASS_ATTR ODFacet;
- class FW_CLASS_ATTR FW_CMouseEvent;
- class FW_CLASS_ATTR ODDragItemIterator;
- class FW_CLASS_ATTR ODDragAndDrop;
-
- //==============================================================================
- // FW_CDragCommand - handles the source side of drag-and-drop
- //==============================================================================
-
- class FW_CLASS_ATTR FW_CDragCommand : public FW_CCommand
- {
- public:
- FW_DECLARE_CLASS
-
- public:
- FW_CDragCommand(Environment* ev,
- FW_CFrame* frame,
- FW_Boolean canUndo);
-
- virtual ~ FW_CDragCommand();
-
- //----------------------------------------------------------------------------------------
- // Inherited API (From FW_CCommand)
- //
- virtual void DoIt(Environment* ev); // Override
- // Don't override.
- // To make drag-move to another part Undo-able, override these methods:
- // UndoIt, RedoIt, SaveUndoState, DoClear
-
- virtual void CommitDone(Environment* ev);
- // Called just before the command is deleted.
- // doneState values are kODDone or kODRedone (ODTypes.h)
- // Default calls FreeUndoState if it's a drag-move to another part
-
- //----------------------------------------------------------------------------------------
- // New API
- //
- public:
- void BeginDrag(Environment* ev, const FW_CMouseEvent& theMouseEvent);
- // Called by frame's Drag method
-
- FW_Boolean IsDragMoveToAnotherPart(Environment* ev);
- // return TRUE if this was a drag-move to another part.
-
- protected:
-
- virtual ODShape* CreateDragShape(Environment* ev, ODFacet* facet);
-
- void AdjustUndo(Environment* ev);
- // Check the drag result, and cancel Undo if the drag was unsuccessful.
-
- void DragCompleted(Environment* ev);
-
- void AbortTransaction(Environment* ev);
- // Clean up the Undo stack if the Drag&Drop operation failed
-
- //----------------------------------------------------------------------------------------
- // Data Members
- //
- protected:
- ODDropResult fDragResult;
-
- private:
- ODRgnHandle fDragRegion;
- ODPart* fDestPart; // part in which selected data was dropped
- FW_Boolean fBeganTransaction; // remember that we added an ODBeginAction
- };
-
- //==============================================================================
- // FW_CDropCommand - handles the destination side of drag-and-drop
- //==============================================================================
-
- class FW_CLASS_ATTR FW_CDropCommand : public FW_CCommand
- {
- public:
- FW_DECLARE_CLASS
-
- public:
- FW_CDropCommand(Environment* ev,
- FW_CPart* itsPart,
- FW_CFrame* frame,
- ODDragItemIterator* dropInfo,
- ODFacet* facet,
- const FW_CPoint& dropPoint,
- FW_Boolean canUndo);
-
- virtual ~ FW_CDropCommand();
-
- //----------------------------------------------------------------------------------------
- // Inherited API (From FW_CCommand)
- //
- virtual void DoIt(Environment* ev); // Override
- // Don't override.
- // To make this command Undo-able, override these methods:
- // UndoIt, RedoIt, SaveRedoState, DoDrop, DoDroppedInSameFrame
-
- virtual void CommitUndone(Environment* ev);
- // Called just before the command is deleted.
- // doneState value is kODUndone (ODTypes.h)
- // Default calls FreeRedoState if it's not a drag-move within the frame
-
- //----------------------------------------------------------------------------------------
- // New API
- //
- public:
- ODDropResult GetDropResult(Environment* ev) const;
-
- protected:
-
- virtual FW_Boolean DoDrop(Environment* ev,
- ODStorageUnit* dropSU,
- const FW_CPoint& mouseOffset,
- const FW_CPoint& dropPoint,
- FW_Boolean isDropMove);
- virtual FW_Boolean DoDroppedInSameFrame(Environment* ev,
- ODStorageUnit* dropSU,
- const FW_CPoint& originPoint,
- const FW_CPoint& dropPoint);
-
- void AdjustUndo(Environment* ev);
- // Check the drop result, and cancel Undo if the drop failed.
-
- void GetDropOrigin(Environment* ev, FW_CPoint& originPoint);
- // Return non-zero value if the source part was moved;
-
- ODDropResult HandleDrop(Environment* ev);
-
- FW_Boolean IsDragMoveInSameFrame(Environment* ev) const;
- ODFacet* GetDropFacet(Environment* ev) const;
-
- //----- Linking/PasteAs -----
- FW_Boolean HandlePasteAsDialog(Environment* ev, ODStorageUnit* dropSU, FW_Boolean& handledDrop, FW_Boolean& createdLink);
- virtual void DoDroppedPasteAs(Environment* ev, const FW_CPoint& originPoint, const FW_CPoint& dropPoint);
-
- virtual FW_Boolean DoPasteAsEmbed(Environment* ev, ODStorageUnit* storageUnit);
- // Override to PasteAs an embedded part.
-
- //----------------------------------------------------------------------------------------
- // Data Members
- //
- protected:
- ODDropResult fDropResult;
-
- private:
- FW_Boolean fDroppedInSameFrame;
- ODFacet* fFacet;
- ODDragItemIterator* fDropItemIterator;
- FW_CPoint fDropPoint; // In content coordinates
- };
-
- //==============================================================================
- // FW_CDropCommand inlines
- //==============================================================================
-
- //--------------------------------------------------------------------
- // FW_CDropCommand::GetDropFacet
- //--------------------------------------------------------------------
- inline ODFacet* FW_CDropCommand::GetDropFacet(Environment* ev) const
- {
- return fFacet;
- }
-
- //--------------------------------------------------------------------
- // FW_CDropCommand::GetDropResult
- //--------------------------------------------------------------------
- inline ODDropResult FW_CDropCommand::GetDropResult(Environment* ev) const
- {
- return fDropResult;
- }
-
- //--------------------------------------------------------------------
- // FW_CDropCommand::IsDragMoveInSameFrame
- //--------------------------------------------------------------------
- inline FW_Boolean FW_CDropCommand::IsDragMoveInSameFrame(Environment* ev) const
- {
- return (fDroppedInSameFrame && fDropResult == kODDropMove);
- }
-
- #if FW_LIB_EXPORT_PRAGMAS
- #pragma lib_export off
- #endif
-
- #endif
-